package com.action
{
	import com.resource.unit.ActionUnit;
	import com.stage.item.Player;
	import com.utils.time.TimerClock;

	public class ActionHurt extends BaseAction
	{
		private var _threadId:int = 0;
		private var _hight:Number = 0;
		private var _currSpeed:Number = 0;
		private var _initSpeed:Number = -10;
		private var _backSpeed:Number = -2;
		
		public function ActionHurt(player:Player)
		{
			super(player);
		}
		
		public override function start(dir:int=1):void{
			_dir = dir;
			if(_threadId == 0){
				_threadId = TimerClock.getInstance().addEnterFrame(enterFrame);
			}
			_player.act = ActionUnit.HURT;
			_player.addActionEndListener(actionEnd);
			_currSpeed = _initSpeed;
		}
		
		public override function end():void{
			_player.act = ActionUnit.STAND;
			_player.removeActionEndListener(actionEnd);
			if(_threadId > 0){
				TimerClock.getInstance().removeEnterFrame(_threadId);
				_threadId = 0;
			}
		}
		
		protected override function enterFrame():void{
			if(_hight + _currSpeed >= 0){
				_player.y -= _hight;
				_hight = 0;
				_player.action = null;
				return;
			}
			_player.x -= _backSpeed * _dir;
			_player.y += _currSpeed;
			_hight += _currSpeed;
			_currSpeed += 1;
		}
		
		private function actionEnd(player:Player):void{
			_player.view.isStop = true;
			
		}
	}
}